#include "sequential_stack.h"


/**
 * @brief 栈初始化
 * @param stack 栈
 */
void SeqStackInit(SeqStack_t *stack)
{
    // 置空栈
    stack->top = -1;
}

/**
 * @brief 判断栈是否为空
 * @param stack 栈
 * @return 栈空返回True，否则返回False
 */
bool SeqStackIsEmpty(const SeqStack_t *stack)
{
    return stack->top == -1;
}

/**
 * @brief 判断栈是否已满
 * @param stack 栈
 * @return 栈满返回True，否则返回False
 */
bool SeqStackIsFull(const SeqStack_t *stack)
{
    return stack->top == MAX_STACK_LENGTH - 1;
}

/**
 * @brief 入栈
 * @param stack 栈
 * @param data 入栈的数据
 * @return {@SeqSackStatus_t}
 */
SeqSackStatus_t SeqStackPush(SeqStack_t *stack, const BrowserData_t *data)
{
    if (SeqStackIsFull(stack)) {
        return SEQ_STACK_FAIL;
    }
    stack->top++;
    stack->browserData[stack->top] = *data;
    return SEQ_STACK_SUCCESS;
}

/**
 * @brief 出栈
 * @param stack 栈
 * @param data 出栈的数据
 * @return {@SeqSackStatus_t}
 */
SeqSackStatus_t SeqStackPop(SeqStack_t *stack, BrowserData_t *data)
{
    if (SeqStackIsEmpty(stack)) {
        return SEQ_STACK_FAIL;
    }
    *data = stack->browserData[stack->top];
    stack->top--;
    return SEQ_STACK_SUCCESS;
}


/**
 * @brief 获取顶栈的数据
 * @param stack 栈
 * @param data 顶栈的数据
 * @return {@SeqSackStatus_t}
 */
SeqSackStatus_t SeqStackGetTop(SeqStack_t *stack, BrowserData_t *data)
{
    if (SeqStackIsEmpty(stack)) {
        return SEQ_STACK_FAIL;
    }
    *data = stack->browserData[stack->top];
    return SEQ_STACK_SUCCESS;
}
